package com.excuse.excusebuilder.presenter;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.excuse.excusebuilder.R;
import com.excuse.excusebuilder.impl.view.MainActivityInterface;
import com.excuse.excusebuilder.view.fragment.CommunityFragment;
import com.excuse.excusebuilder.view.fragment.HomeFragment;
import com.excuse.excusebuilder.view.fragment.MineFragment;

/**
 * Created by U-nookia on 2017/4/14.
 */

public class MainActivityPresenter {

    private MainActivityInterface mainActivity;
    private Context context;

    private HomeFragment homeFragment;
    private CommunityFragment communityFragment;
    private MineFragment mineFragment;
    private FragmentManager manager;

    public MainActivityPresenter(Context context,MainActivityInterface mainActivity) {
        this.mainActivity = mainActivity;
        this.context = context;
        initFragmentManager();
        initFragment();
    }

    private void initFragmentManager() {
        manager = mainActivity.getActivityFragmentManager();
    }

    private void initFragment() {
        homeFragment = new HomeFragment();
        communityFragment = new CommunityFragment();
        mineFragment = new MineFragment();
    }

    public void setHomeFragment() {
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frame,homeFragment);
        transaction.commit();
    }

    public void setCommunityFragment() {
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frame,communityFragment);
        transaction.commit();
    }

    public void setMineFragment() {
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frame,mineFragment);
        transaction.commit();
    }
}
